package com.manage.competition.service.impl;

import com.manage.competition.entity.Organizer;
import com.manage.competition.mapper.OrganizerMapper;
import com.manage.competition.repository.OrganizerRepository;
import com.manage.competition.service.IOrganizerService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 15:05 2019/3/31
 * @Description:
 */
@Service
public class OrganizerServiceImpl implements IOrganizerService {

    @Autowired
    private OrganizerMapper organizerMapper;

    @Autowired
    private OrganizerRepository organizerRepository;

    @Override
    public int insert(Organizer organizer) {
        organizer.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        organizer.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return organizerMapper.insert(organizer);
    }

    @Override
    public int update(Organizer organizer) {
        organizer.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return organizerMapper.updateByPrimaryKeySelective(organizer);
    }

    @Override
    public Organizer getById(long id) {
        return organizerRepository.findById(id).orElse(null);
    }

    @Override
    public int deleteByPrimaryKey(Long organizerId) {
        return organizerMapper.deleteByPrimaryKey(organizerId);
    }
}
